package com.neuedu.javase.thread;

import java.util.ArrayList;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-10-05 15:29
 * 描述 :
 */
public class MyRunnable  implements Runnable {
    public boolean running = false;


    public void stop(){
        running = false;
    }
    public void setRunning(boolean running) {
        this.running = running;
    }

    @Override
    public void run() {
        running = true;
        //子任务
        for (int i = 0; i < 10 && running; i++) {
            System.out.println("MyRunnable i = " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
